package com.jsgt.greekfire.ui.mainassets.coindetail

import androidx.viewpager.widget.ViewPager
import com.fhx.core.base.BaseActivity
import com.fhx.core.base.BaseFragment
import com.flyco.tablayout.listener.CustomTabEntity
import com.flyco.tablayout.listener.OnTabSelectListener
import com.jsgt.greekfire.R
import com.jsgt.greekfire.ui.mainassets.adapter.TabEntity
import com.jsgt.greekfire.ui.mainassets.coindetail.CoinNewDetailFragment.Companion.TYPE_ALL
import com.jsgt.greekfire.ui.mainassets.coindetail.CoinNewDetailFragment.Companion.TYPE_EXPENDITURE
import com.jsgt.greekfire.ui.mainassets.coindetail.CoinNewDetailFragment.Companion.TYPE_INCOME
import com.jsgt.greekfire.ui.trading.adapter.PagerAdapter
import kotlinx.android.synthetic.main.activity_coin_new_detail.*
import kotlinx.android.synthetic.main.view_title.*

class CoinNewDetailActivity : BaseActivity() {
    private var assetGuid: Int? = null
    private var symbol: String? = null
    private var mTabEntities =
        ArrayList<CustomTabEntity>()
    private val mFragments: MutableList<BaseFragment> = ArrayList()
    override fun getLayoutId(): Int = R.layout.activity_coin_new_detail

    override fun main() {
        assetGuid = intent.getIntExtra("assetGuid",-1)
        symbol = intent.getStringExtra("symbol")
        title_tv?.text = resources.getString(R.string.coin_new_detail_title)
        val tabArray =
            resources.getStringArray(R.array.tab_coin_detail_list)
        val tabs = java.util.ArrayList<String>()

        mFragments.add(CoinNewDetailFragment.newInstance(TYPE_ALL,assetGuid!!,symbol!!)) //全部
        mFragments.add(CoinNewDetailFragment.newInstance(TYPE_INCOME,assetGuid!!,symbol!!)) //收入
        mFragments.add(CoinNewDetailFragment.newInstance(TYPE_EXPENDITURE,assetGuid!!,symbol!!)) //支出
        for (i in tabArray.indices) {
            mTabEntities.add(TabEntity(tabArray!![i]))
            tabs.add(tabArray[i])
        }
        viewPager.adapter = PagerAdapter(
            supportFragmentManager,
            mFragments,
            tabs
        )
        tl_2()
    }

    private fun tl_2() {
        tlCoinNewDetail.setTabData(mTabEntities)
        tlCoinNewDetail.setOnTabSelectListener(object : OnTabSelectListener {
            override fun onTabSelect(position: Int) {
                viewPager.setCurrentItem(position)

            }

            override fun onTabReselect(position: Int) {}
        })
        viewPager.addOnPageChangeListener(object : ViewPager.OnPageChangeListener {
            override fun onPageScrolled(
                position: Int,
                positionOffset: Float,
                positionOffsetPixels: Int
            ) {
            }

            override fun onPageSelected(position: Int) {
                tlCoinNewDetail.setCurrentTab(position)
            }

            override fun onPageScrollStateChanged(state: Int) {}
        })
        viewPager.setCurrentItem(0)
    }

}